package cc.htdf.gwc.radar.controller;

import cc.htdf.gwc.radar.service.ForecastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import whisper.common.utils.FileUtils;

/**
 * Created by JT on 2017/11/13.
 */
@RestController
@RequestMapping("/data")
public class ForecastController {

    @Value("${repository.file}")
    private String fileRepository;

    @Autowired
    private ForecastService forecastService;

    @GetMapping(value = "/file/forecast/parse")
    public void fileParsing(@RequestParam("filename") String filename) {
        /* 文件全路径 */
        String[] baseDirs = fileRepository.split(",");
        String[] fullpath = new String[baseDirs.length];
        for (int i = 0; i < baseDirs.length; i++) {
            fullpath[i] = baseDirs[i] + filename;
        }

        int index = FileUtils.checkFilesExists(fullpath);
        forecastService.fileParsing(fullpath[index]);

    }
}
